package cn.jetpiece.cloud.dict.api;


import cn.jetpiece.cloud.dict.api.model.params.CreateCategoryParam;
import cn.jetpiece.cloud.dict.api.model.params.UpdateCategoryParam;
import cn.jetpiece.cloud.dict.api.model.query.CategoryQuery;
import cn.jetpiece.cloud.dict.api.model.result.CategoryResult;
import cn.jetpiece.cloud.model.model.DictModel;
import cn.jetpiece.cloud.model.model.TreeSelectResult;
import cn.jetpiece.cloud.model.page.PageResult;
import cn.jetpiece.cloud.model.response.Result;
import cn.jetpiece.cloud.resource.annotation.annotation.ApiResource;
import cn.jetpiece.cloud.resource.annotation.annotation.ScanResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


/**
 * @author hancp
 * @version 1.0
 * @description: 分类字典
 * @date 2021/12/6 11:20
 */

@Api(tags = "分类设置")
@ApiResource
public interface CategoryApi {
    String SERVER_API = "/${jetpiece.common.path:common}";

    String API = SERVER_API + "/categories";

    /**
     * 分页列表查询
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取分页列表", notes = "获取分页列表")
    @ScanResource(value = API, method = RequestMethod.GET)
    Result<PageResult<CategoryResult>> queryPageList(@SpringQueryMap CategoryQuery query);

    /**
     * 子分类
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取子节点列表", notes = "获取子节点列表")
    @ScanResource(value = API + "/children/{pid}", method = RequestMethod.GET)
    Result<List<CategoryResult>> listChildren(@PathVariable(name = "pid") String pid, @SpringQueryMap CategoryQuery query);

    /**
     * 添加
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "添加分类", notes = "添加分类")
    @ScanResource(value = API, method = RequestMethod.POST)
    Result<CategoryResult> add(@RequestBody CreateCategoryParam param);

    /**
     * 编辑
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "编辑分类", notes = "编辑分类")
    @ScanResource(value = API, method = RequestMethod.PUT)
    Result<CategoryResult> edit(@RequestBody UpdateCategoryParam param);

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除分类", notes = "删除分类")
    @ScanResource(value = API + "/{id}", method = RequestMethod.DELETE)
    Result<CategoryResult> delete(@PathVariable(name = "id") String id);

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除分类", notes = "批量删除分类")
    @ScanResource(value = API + "/delete-batch", method = RequestMethod.DELETE)
    Result<CategoryResult> deleteBatch(@RequestParam(name = "ids") String ids);

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "通过ID获取数据", notes = "通过ID获取数据")
    @ScanResource(value = API + "/{id}", method = RequestMethod.GET)
    Result<CategoryResult> queryById(@PathVariable(name = "id") String id);

    /**
     * 加载单个数据 用于回显
     *
     * @param field
     * @param val
     * @return
     */
    @ApiOperation(value = "加载单个数据", notes = "加载单个数据")
    @ScanResource(value = API + "/field/{field}/value/{val}", method = RequestMethod.GET)
    Result<CategoryResult> getByFieldVal(@PathVariable(name = "field") String field, @PathVariable(name = "val") String val);

    /**
     * 加载节点的子数据
     *
     * @param pid
     * @return
     */
    @ApiOperation(value = "树形结构-加载节点子数据", notes = "树形结构-加载节点子数据")
    @ScanResource(value = API + "/list-tree-children/{pid}", method = RequestMethod.GET)
    Result<List<TreeSelectResult>> listTreeChildren(@PathVariable(name = "pid") Long pid);

    /**
     * 加载一级节点/如果是同步 则所有数据
     *
     * @param pCode
     * @param async
     * @return
     */
    @ApiOperation(value = "树形结构-通过Code获取节点数据", notes = "树形结构-通过Code获取节点数据")
    @ScanResource(value = API + "/list-tree-root/code/{pCode}/async/{async}", method = RequestMethod.GET)
    Result<List<TreeSelectResult>> listTreeRoot(@PathVariable(name = "pCode") String pCode, @PathVariable(name = "async") Boolean async);

    /**
     * 校验编码
     *
     * @param code
     * @return
     */
    @ApiOperation(value = "校验分类名称和编码", notes = "校验分类名称和编码")
    @ScanResource(value = API + "/code-check", method = RequestMethod.GET)
    Result<String> checkCode(@RequestParam(name = "name", required = false) String name, @RequestParam(name = "code", required = false) String code);

    /**
     * 分类字典树控件 加载节点
     *
     * @param pid
     * @param pcode
     * @param condition
     * @return
     */
    @ApiOperation(value = "树形结构-加载节点数据", notes = "树形结构-加载节点数据")
    @ScanResource(value = API + "/list-tree", method = RequestMethod.GET)
    Result<List<TreeSelectResult>> loadDict(@RequestParam(name = "pid", required = false) Long pid, @RequestParam(name = "pcode", required = false) String pcode,
                                            @RequestParam(name = "condition", required = false) String condition);

    /**
     * 分类字典控件数据回显[表单页面]
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "分类字典-控件数据回显", notes = "分类字典-控件数据回显")
    @ScanResource(value = API + "/list-texts/{ids}", method = RequestMethod.GET)
    Result<List<String>> loadDictItem(@PathVariable(name = "ids") String ids);

    /**
     * [列表页面]加载分类字典数据 用于值的替换
     *
     * @param code
     * @return
     */
    @ApiOperation(value = "分类字典-通过Code获取节点数据", notes = "分类字典-通过Code获取节点数据")
    @ScanResource(value = API + "/list-all/{code}", method = RequestMethod.GET)
    Result<List<DictModel>> loadAllData(@PathVariable(name = "code") String code);

    /**
     * 根据父级id批量查询子节点
     *
     * @param parentIds
     * @return
     */
    @ApiOperation(value = "批量查询子节点数据", notes = "批量查询子节点数据")
    @ScanResource(value = API + "/children/batch", method = RequestMethod.GET)
    Result<List<CategoryResult>> getChildListBatch(@RequestParam(name = "parentIds") String parentIds);

    /**
     * 通过Code查询
     *
     * @param
     * @return
     */
    @ApiOperation(value = "通过CODE获取数据", notes = "通过CODE获取数据")
    @ScanResource(value = API + "/code/{code}", method = RequestMethod.GET)
    Result<CategoryResult> queryByCode(@PathVariable(name = "code") String code);

    /**
     * 获取父级编码规则
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取父级编码规则", notes = "获取父级编码规则")
    @ScanResource(value = API + "/parent-rule/{id}", method = RequestMethod.GET)
    Result<CategoryResult> queryParentRuleById(@PathVariable(name = "id") String id);

    /**
     * 启用/禁用
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    @ScanResource(value = API + "/{id}/enable-flag/{flag}", method = RequestMethod.PATCH)
    Result<List<String>> setEnableFlag(@PathVariable(name = "id") String id, @PathVariable(name = "flag") Integer flag);

    /**
     * 通过ID获取所有的子分类信息
     *
     * @param id
     * @param isContainFlag 是否包含自己 { {1:包含 0:不包含}}
     * @return
     */
    @ApiOperation(value = "通过ID获取所有的子分类信息", notes = "通过ID获取所有的子分类信息")
    @ScanResource(value = API + "/{id}/all-children", method = RequestMethod.GET)
    Result<List<CategoryResult>> queryAllChildrenByPid(@PathVariable(name = "id") String id, @RequestParam(name = "isContainFlag", required = false) Integer isContainFlag);

}
